package com.axjy.his.controller;

import com.axjy.his.pojo.User;
import com.axjy.his.service.UserService;
import com.axjy.his.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by lenovo on 2017/11/9.
 */
@RestController
@RequestMapping("/sys/user")
public class UserController {

    @Resource
    private UserService users;

    public String msg;

    @RequestMapping("/selectAllUser")
    public List<User> selectAllUser(){
        return users.selectAllUser();
    }
    @PostMapping("/grant")
    public String grant(Integer userId,Integer roleId){
        try {
            users.grant(userId, roleId);
            msg="用户授权成功";
        }catch (RuntimeException ex){
            msg="用户授权失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

}
